#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QString History="";
    str_breakfirst_kll="139";//早餐卡路里默认值
    str_breakfirst_names="鸡蛋";//早餐默认值
    str_breakfirst_nums="1";//默认为一

    str_lunch_names="米饭";//午餐默认值
     str_lunch_nums="1";//午餐数量默认值默认为一
     str_lunch_kll="116";//午餐卡路里默认值

     str_dinner_names="胡罗卜";
     str_dinner_nums="1";
     str_dinner_kll="32";
}

Widget::~Widget()
{
    delete ui;
}

//用来接收早餐食物，并赋予卡路里值
void Widget::on_breakFirstKinds_currentIndexChanged(int index)
{
    switch (index) {
    case 0:
        str_breakfirst_kll="139";//鸡蛋
        str_breakfirst_names="鸡蛋";
        break;
    case 1:
        str_breakfirst_kll="50";//稀饭
        str_breakfirst_names="稀饭";
        break;
    case 2:
        str_breakfirst_kll="31";//苹果
        str_breakfirst_names="苹果";
        break;
    case 3:
        str_breakfirst_kll="313";//面包
        str_breakfirst_names="面包";
        break;
    case 4:
        str_breakfirst_kll="227";//包子
        str_breakfirst_names="包子";
        break;
    default:
        break;
    }
}
//用来接收早餐数量
void Widget::on_breakfirstNums_currentIndexChanged(int index)
{
  str_breakfirst_nums=QString::number(index+1);
}
//计算总热量
void Widget::on_pushButton_clicked()
{
   int  res_bre=str_breakfirst_kll.toInt()*str_breakfirst_nums.toInt();
   int  res_lun=str_lunch_kll.toInt()*str_lunch_nums.toInt();
   int  res_din=str_dinner_kll.toInt()*str_dinner_nums.toInt();
  int  res=res_bre+res_lun+res_din;
    ui->result->setText(QString::number(res));
    History+="今日摄入: 早餐: "+str_breakfirst_names+"午餐: "+str_lunch_names+"晚餐: "+str_dinner_names+"共计: "+QString::number(res)+" 大卡！";
      ui->history->setText(History);
}
//用来接收午餐食物，并赋予卡路里值
void Widget::on_lunchkinds_currentIndexChanged(int index)
{

    switch (index) {
    case 0:
        str_lunch_kll="116";//米饭
        str_lunch_names="米饭";
        break;
    case 1:
        str_lunch_kll="301";//猪肉
        str_lunch_names="猪肉";
        break;
    case 2:
        str_lunch_kll="395";//排骨
        str_lunch_names="排骨";
        break;
    case 3:
        str_lunch_kll="101";//生菜
        str_lunch_names="生菜";
        break;
    case 4:
        str_lunch_kll="167";//里脊
        str_lunch_names="里脊";
        break;
    default:
        break;
    }
}
//用来接收午餐数量
void Widget::on_lunchNums_currentIndexChanged(int index)
{
    str_lunch_nums=QString::number(index+1);
}

void Widget::on_dinnerKinds_currentIndexChanged(int index)
{
    switch (index) {
    case 0:
        str_dinner_kll="32";//胡萝卜
        str_dinner_names="胡萝卜";
        break;
    case 1:
        str_dinner_kll="48";//虾仁
        str_dinner_names="虾仁";
        break;
    case 2:
        str_dinner_kll="11";//冬瓜
        str_dinner_names="冬瓜";
        break;
    case 3:
        str_dinner_kll="22";//南瓜
        str_dinner_names="南瓜";
        break;
    case 4:
        str_dinner_kll="58";//蓝莓
        str_dinner_names="蓝莓";
        break;
    default:
        break;
    }
}

void Widget::on_dinnerNums_currentIndexChanged(int index)
{
    str_dinner_nums=QString::number(index+1);
}
//删除早餐数据
void Widget::on_breakfirstDeleat_clicked()
{
    str_breakfirst_kll="";//早餐卡路里默认值
    str_breakfirst_names="";//早餐默认值
    str_breakfirst_nums="1";//默认为一

}
//删除午餐数据
void Widget::on_lunchDelead_clicked()
{
    str_lunch_names="";//午餐默认值
     str_lunch_nums="1";//午餐数量默认值默认为一
     str_lunch_kll="";//午餐卡路里默认值


}
//删除晚餐数据
void Widget::on_dinnerDelead_clicked()
{
     str_dinner_names="";
     str_dinner_nums="1";
     str_dinner_kll="";
}

void Widget::on_comboBox_3_currentIndexChanged(int index)
{
    switch (index) {
    case 0:
        str_breakfirst_kll="139";//鸡蛋
        str_breakfirst_names="鸡蛋";
        break;
    case 1:
        str_breakfirst_kll="31";//苹果
        str_breakfirst_names="苹果";
        break;

    case 2:
        str_breakfirst_kll="50";//稀饭
        str_breakfirst_names="稀饭";
        break;
    case 3:
        str_breakfirst_kll="313";//面包
        str_breakfirst_names="面包";
        break;
    case 4:
        str_breakfirst_kll="227";//包子
        str_breakfirst_names="包子";
        break;
    default:
        break;
    }
    ui->kklbreakfirst->setText(str_breakfirst_names+"的卡路里是："+str_breakfirst_kll+"卡/100g");
    History+=str_breakfirst_names+"的卡路里是："+str_breakfirst_kll+"卡/100g!";
    ui->history->setText(History);
}

void Widget::on_comboBox_currentIndexChanged(int index)
{

    switch (index) {
    case 0:
        str_lunch_kll="116";//米饭
        str_lunch_names="米饭";
        break;
    case 1:
        str_lunch_kll="301";//猪肉
        str_lunch_names="猪肉";
        break;
    case 2:
        str_lunch_kll="395";//排骨
        str_lunch_names="排骨";
        break;
    case 3:
        str_lunch_kll="101";//生菜
        str_lunch_names="生菜";
        break;
    case 4:
        str_lunch_kll="167";//里脊
        str_lunch_names="里脊";
        break;
    default:
        break;
    }
    ui->kkllunch->setText(str_lunch_names+"的卡路里是："+str_lunch_kll+"卡/100g");
    History+=str_lunch_names+"的卡路里是："+str_lunch_kll+"卡/100g!";
    ui->history->setText(History);
}

void Widget::on_comboBox_2_currentIndexChanged(int index)
{
    switch (index) {
    case 0:
        str_dinner_kll="32";//胡萝卜
        str_dinner_names="胡萝卜";
        break;
    case 1:
        str_dinner_kll="48";//虾仁
        str_dinner_names="虾仁";
        break;
    case 2:
        str_dinner_kll="11";//冬瓜
        str_dinner_names="冬瓜";
        break;
    case 3:
        str_dinner_kll="22";//南瓜
        str_dinner_names="南瓜";
        break;
    case 4:
        str_dinner_kll="58";//蓝莓
        str_dinner_names="蓝莓";
        break;
    default:
        break;
    }
    ui->kkldinner->setText(str_dinner_names+"的卡路里是："+str_dinner_kll+"卡/100g");
    History+=str_dinner_names+"的卡路里是："+str_dinner_kll+"卡/100g!";
    ui->history->setText(History);
}
